<?php
/**
 * 用户类
 * @author ran
 * date 2016-04-26
 */
namespace wap\controllers;

use Yii;

class CustomController extends  WeiXinOAtuhController
{
    /**
     * 优选uid
     * @var string
     */
    public $bestry_uid;
    /**
     * 喜试uid
     * @var string
     */
    public $liketry_uid;
    
    /**
     * 微信openid
     * @var string
     */
    public $openid;
    
    /**
     * 微信配置项，键名为\common\config\share.php
     * @var string
     */
    public $layout_data='';
    
    /**
     * body样式
     * @var string
     */
    public $bodyClass;
    
    public function init() {
        parent::init();
        $this->enableCsrfValidation = false;
        
        $this->login_url = $this->login_url.urlencode(Yii::$app->request->getHostInfo().Yii::$app->request->url);
    }
    
    public function beforeAction($action)
    {
        
        $userIp = Yii::$app->request->getUserIP();
        if($userIp == '127.0.0.1' || $userIp == '::1') {
            $this->session->set(Yii::$app->params['wap_uid'], 1);
            $this->session->set(Yii::$app->params['wap_bestry_uid'], 1522091);
            $this->session->set(Yii::$app->params['wx_open_id'], 'onaj7ww6Dta8fBtKjOFT9Lc7-PxI');
        }

        $this->liketry_uid = intval($this->session->get(Yii::$app->params['wap_uid']),null);
        $this->bestry_uid = intval($this->session->get(Yii::$app->params['wap_bestry_uid']),null);
        $this->openid = $this->session->get(Yii::$app->params['wx_open_id'],null);

        return parent::beforeAction($action);
        
    }

    public function actions()
    {
        return parent::actions()+['error' => [
            'class' => 'yii\web\ErrorAction',
        ]];
    }
    
    /**
     * 判断用户是否登陆
     * @return boolean
     */
    protected function isLogin()
    {
        if($this->bestry_uid) {
            return true;
        }
        return false;
    }
    
    /**
     * 格式化金额
     * @param unknown $money
     */
    protected static function  formatDecimal($money){
        return Yii::$app->formatter->asDecimal($money,2);
    }
}
